package com.liu.stockmarket.ui.self

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.liu.stockmarket.R
import com.liu.stockmarket.utils.getString
import java.math.BigDecimal

class HeaderAdapter :
    BaseQuickAdapter<SelfAdapter.Item, BaseViewHolder>(R.layout.item_composite_index) {
    override fun convert(holder: BaseViewHolder, item: SelfAdapter.Item) {
        holder.setText(R.id.tv_name, item.name)

        val nowPrice = holder.getView<TextView>(R.id.tv_now_price)
        val upOrDown = holder.getView<TextView>(R.id.tv_up_or_down)
        val color = when {
            item.upOrDownMoney < BigDecimal.ZERO -> {
                context.getColor(R.color.down)
            }
            item.upOrDownMoney >= BigDecimal.ZERO -> {
                context.getColor(R.color.up)
            }
            else ->   context.getColor(R.color.up)
        }

        nowPrice.setTextColor(color)
        nowPrice.text = item.nowPrice.getString()

        upOrDown.setTextColor(color)
        upOrDown.text = "${item.upOrDownMoney} ${item.upOrDownPercent}%"

    }
}